home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 012a / lib194.zip / TIME.PRG < prev    next >
Text File  |  1992-12-23  |  8KB  |  213 lines

  1. *-------------------------------------------------------------------------------
  2. *-- Program...: TIME.PRG
  3. *-- Programmer: Ken Mayer (CIS: 71333,1030)
  4. *-- Date......: 06/25/1992
  5. *-- Notes.....: These are a series of routines that deal with time strings,
  6. *--             and so on. Very useful. See README.TXT for more details on
  7. *--             the use of this library file.
  8. *-------------------------------------------------------------------------------
  9.  
  10. FUNCTION Delay
  11. *-------------------------------------------------------------------------------
  12. *-- Programmer..: Jay Parsons (CIS: 70160,340)
  13. *-- Date........: 03/01/92
  14. *-- Notes.......: Delay Loop.  Returns .T. after lapse of given number of 
  15. *--               seconds. Accurate only to within one second.
  16. *--               <some published ways to do this do not work, because they 
  17. *--               ignore the possibility that the interval may start at 59 
  18. *--               seconds, and thus that the ending number of seconds will be 
  19. *--               smaller.>
  20. *-- Written for.: dBASE IV
  21. *-- Rev. History: None
  22. *-- Calls.......: TIME2SEC()           Function in TIME.PRG
  23. *-- Called by...: Any
  24. *-- Usage.......: Delay(<nSeconds>)
  25. *-- Example.....: lX= Delay(10)
  26. *-- Returns.....: Logical
  27. *-- Parameters..: nSeconds = number of seconds to delay
  28. *-------------------------------------------------------------------------------
  29.  
  30.     parameters nSeconds         && up to 86400, one day
  31.     private nTimeout
  32.     nTimeout = mod( Time2Sec( time() ) + nSeconds, 86400 )
  33.    do while Time2Sec( time() ) # nTimeout
  34.        *-- Nothing to do ...
  35.     enddo
  36.  
  37. RETURN .T.
  38. *-- EoF: Delay()
  39.  
  40. FUNCTION Time2Sec
  41. *-------------------------------------------------------------------------------
  42. *-- Programmer..: Jay Parsons (CIS: 70160,340)
  43. *-- Date........: 03/01/92
  44. *-- Notes.......: Convert HH:MM:SS or HH:MM:SS.SS string to seconds.
  45. *-- Written for.: dBASE IV
  46. *-- Rev. History: None
  47. *-- Calls.......: None
  48. *-- Called by...: Any
  49. *-- Usage.......: Time2Sec("<cTime>")
  50. *-- Example.....: ?Time2Sec("01:24:15")
  51. *-- Returns.....: Numeric
  52. *-- Parameters..: cTime = Time string in format HH:MM:SS or HH:MM:SS.SS
  53. *-------------------------------------------------------------------------------
  54.     
  55.     parameters cTime
  56.     private cTemp, nSecs
  57.     cTemp = cTime
  58.     nSecs = 3600 * val( cTemp )
  59.     cTemp = substr( cTemp, at( ":", cTemp ) + 1 )
  60.     nSecs = nSecs + 60 * val( cTemp )
  61.     
  62. RETURN nSecs + val( substr( cTemp, at( ":", cTemp ) + 1 ) )
  63. *-- EoF: Time2Sec()
  64.  
  65. FUNCTION Sec2Time
  66. *-------------------------------------------------------------------------------
  67. *-- Programmer..: Jay Parsons (CIS: 70160,340)
  68. *-- Date........: 03/01/92
  69. *-- Notes.......: Convert number of seconds to time string in format of
  70. *--               HH:MM:SS or HH:MM:SS.SS.
  71. *-- Written for.: dBASE IV
  72. *-- Rev. History: None
  73. *-- Calls.......: None
  74. *-- Called by...: Any
  75. *-- Usage.......: Sec2Time("<cTime>")
  76. *-- Example.....: ?Sec2Time(30001.3)
  77. *-- Returns.....: Character String
  78. *-- Parameters..: nSeconds = Seconds to be converted 
  79. *-------------------------------------------------------------------------------
  80.  
  81.     parameters nSeconds
  82.     private nHrs, nMins , nSecs, cTemp
  83.     nSecs = mod( nseconds, 86400 )
  84.     nHrs  = int( nSecs / 3600 )
  85.     nSecs = nSecs - nHrs * 3600
  86.     nMins = int( nSecs / 60 )
  87.     nSecs = nSecs - nMins * 60
  88.     cTemp = transform( nHrs, "@L 99" ) + ":" + transform( nMins, "@L 99" ) ;
  89.       + ":"
  90.  
  91. RETURN cTemp+iif(nSecs=int(nSecs),transform(nSecs,"@L 99"),;
  92.                  transform(nSecs,"@L 99.99"))
  93. *-- EoF: Sec2Time()
  94.  
  95. FUNCTION DiffTime
  96. *-------------------------------------------------------------------------------
  97. *-- Programmer..: Jay Parsons (CIS: 70160,340)
  98. *-- Date........: 03/01/92
  99. *-- Notes.......: Calculate difference between two times given as HH:MM:SS 
  100. *--               strings. If second time is smaller than first, assumes 
  101. *--               midnight passage. Returns HH:MM:SS string, or HH:MM:SS.SS 
  102. *--               string if fractional seconds passed.
  103. *-- Rev. History: None
  104. *-- Written for.: dBASE IV
  105. *-- Rev. History: None
  106. *-- Calls.......: TIME2SEC()           Function in TIME.PRG
  107. *--               SEC2TIME()           Function in TIME.PRG
  108. *-- Called by...: Any
  109. *-- Usage.......: DiffTime("<cTime1>","<cTime2>")
  110. *-- Example.....: ?DiffTime("2:03:24","5:12:33")
  111. *-- Returns.....: Character String
  112. *-- Parameters..: cTime1 = Time to subtract from cTime2
  113. *--               cTime2 = Time to subtract from (larger value, unless
  114. *--                            after midnite)
  115. *-------------------------------------------------------------------------------
  116.  
  117.     parameters cTime1, cTime2
  118.  
  119. RETURN Sec2Time( 86400 + Time2Sec( cTime2 ) - Time2Sec( cTime1 ) )
  120. *-- EoF: DiffTime()
  121.  
  122. FUNCTION Civ2Mil
  123. *-------------------------------------------------------------------------------
  124. *-- Programmer..: Jay Parsons (CIS: 70160,340)
  125. *-- Date........: 03/01/92
  126. *-- Notes.......: Converts string like "12:59 a.m." to standard 24-hour 
  127. *--               HH:MM:SS. If the string contains neither "a" nor "p", the 
  128. *--               hours will not be converted.
  129. *-- Rev. History: None
  130. *-- Written for.: dBASE IV
  131. *-- Rev. History: None
  132. *-- Calls.......: None
  133. *-- Called by...: Any
  134. *-- Usage.......: Civ2Mil("<cCivilTime>")
  135. *-- Example.....: ?Civ2Mil("2:03:24 a.m.")
  136. *-- Returns.....: Character String
  137. *-- Parameters..: cCivilTime = Time to convert to 24 hour time.
  138. *-------------------------------------------------------------------------------
  139.  
  140.     parameters cCiviltime
  141.     private cTstring, nTime
  142.     cTstring =  trim( lower( cCiviltime ) )
  143.     nTime = val( cTstring )
  144.     do case
  145.       case "p" $ cTstring
  146.         cTstring = left( cTstring, at( "p", cTstring ) - 1 )
  147.             nTime = mod( nTime, 12 ) + 12
  148.       case "a" $ cTstring
  149.         cTstring = left( cTstring, at( "a", cTstring ) - 1 )
  150.         nTime = mod( nTime, 12 )
  151.     endcase
  152.     cTstring = transform( nTime, "@L 99" ) ;
  153.       + trim( substr( cTstring, at( ":", cTstring ) ) )
  154.     
  155. RETURN cTstring + iif( len( cTstring ) = 5, ":00", "" )
  156. *-- EoF: Civ2Mil()
  157.  
  158. FUNCTION Mil2Civ
  159. *-------------------------------------------------------------------------------
  160. *-- Programmer..: Jay Parsons (CIS: 70160,340)
  161. *-- Date........: 03/01/92
  162. *-- Notes.......: Converts HH:MM:SS 24-hour string to a.m or p.m. notation.
  163. *-- Rev. History: None
  164. *-- Written for.: dBASE IV
  165. *-- Rev. History: None
  166. *-- Calls.......: None
  167. *-- Called by...: Any
  168. *-- Usage.......: Mil2Civ("<cMilTime>")
  169. *-- Example.....: ?Mil2Civ("14:03:24")
  170. *-- Returns.....: Character String
  171. *-- Parameters..: cMilTime = Time to convert to 24 hour time.
  172. *-------------------------------------------------------------------------------
  173.  
  174.     parameters cMiltime
  175.     private cCivtime, nHours, cMins
  176.     cCivtime = ltrim( trim( cMiltime ) )
  177.     nHours = val( cCivtime )
  178.     cMins = substr( cCivtime, at( ":", cCivtime ) ) + " " ;
  179.       + iif( nHours > 11, "p.m.", "a.m." )
  180.     
  181. RETURN ltrim( str( mod( nHours + 11, 12 ) + 1 ) ) + cMins
  182. *-- EoF: Mil2Civ()
  183.  
  184. FUNCTION IsAmPm
  185. *-------------------------------------------------------------------------------
  186. *-- Programmer..: Charles Miedzinksi (Borland Technical Support)
  187. *-- Date........: 11/05/1992
  188. *-- Notes.......: Taken from TechNotes (??), Checks to see if a character
  189. *--               string is in proper AM/PM time format.
  190. *-- Written for.: dBASE IV 1.1, 1.5
  191. *-- Rev. History: Modified a bit for the Library ...
  192. *-- Calls.......: None
  193. *-- Called by...: Any
  194. *-- Usage.......: IsAmPm(<cTime>)
  195. *-- Example.....: ?IsAmPm("20:15:05")   && should return .F.
  196. *-- Returns.....: Logical
  197. *-- Parameters..: cTime = a time string in format: "HH:MM:SS a/pm"
  198. *--                       Seconds part of string is optional, as is A/PM
  199. *-------------------------------------------------------------------------------
  200.     
  201.     parameters cTime
  202.  
  203. RETURN iif(val(left(cTime, 2)) > = 1 .and. val(left(cTime, 2)) < = 12, ;
  204.      iif(val(substr(cTime, 4, 2)) > = 0 .and. val(substr(cTime, 4, 2)) < = 59, ;
  205.      iif(substr(cTime, 6, 1) $ 'aApP', .T., ;
  206.      iif(val(substr(cTimer, 6, 2)) > = 0 .and. val(substr(cTime, 6, 2)) < = 59, ;
  207.      .T., .F.)), .F.), .F.)
  208. *-- EoF: IsAmPm()
  209.  
  210. *-------------------------------------------------------------------------------
  211. *-- EoP: TIME.PRG
  212. *-------------------------------------------------------------------------------
  213.